package com.party.core.service.mall.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.mall.MallShowSubjectReadDao;
import com.party.core.dao.write.mall.MallShowSubjectWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.mall.MallShowSubject;
import com.party.core.model.mall.MallShowSubjectQuery;
import com.party.core.model.mall.MallShowSubjectWithAuthor;
import com.party.core.service.mall.IMallShowSubjectService;
import com.sun.istack.NotNull;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * 展示商品主题实现
 * Created by wei.li
 *
 * @date 2017/8/24 0024
 * @time 15:19
 */
@Service
public class MallShowSubjectService implements IMallShowSubjectService {

    @Autowired
    private MallShowSubjectWriteDao mallShowSubjectWriteDao;

    @Autowired
    private MallShowSubjectReadDao mallShowSubjectReadDao;

    /**
     * 新增
     * @param mallShowSubject 专题
     * @return 编号
     */
    @Override
    public String insert(MallShowSubject mallShowSubject) {
        BaseModel.preInsert(mallShowSubject);
        boolean result = mallShowSubjectWriteDao.insert(mallShowSubject);
        if (result){
            return mallShowSubject.getId();
        }
        return null;
    }

    /**
     * 更新
     * @param mallShowSubject 专题
     * @return 更新结果（true/false）
     */
    @Override
    public boolean update(MallShowSubject mallShowSubject) {
        return mallShowSubjectWriteDao.update(mallShowSubject);
    }

    /**
     * 逻辑删除
     * @param id 实体主键
     * @return 删除结果（true/false）
     */
    @Override
    public boolean deleteLogic(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return mallShowSubjectWriteDao.deleteLogic(id);
    }

    /**
     * 物理删除
     * @param id 实体主键
     * @return 删除结果（true/false）
     */
    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return mallShowSubjectWriteDao.delete(id);
    }

    /**
     * 批量逻辑删除
     * @param ids 主键集合
     * @return 删除结果(true/false)
     */
    @Override
    public boolean batchDeleteLogic(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return mallShowSubjectWriteDao.batchDeleteLogic(ids);
    }

    /**
     * 批量物理删除
     * @param ids 主键集合
     * @return 删除结果（true/false）
     */
    @Override
    public boolean batchDelete(@NotNull Set<String> ids) {
        return mallShowSubjectWriteDao.batchDelete(ids);
    }

    /**
     * 获取专题
     * @param id 主键
     * @return 专题
     */
    @Override
    public MallShowSubject get(String id) {
        return mallShowSubjectReadDao.get(id);
    }

    /**
     * 分页查询
     * @param mallShowSubject 专题
     * @param page 分页信息
     * @return 列表
     */
    @Override
    public List<MallShowSubject> listPage(MallShowSubject mallShowSubject, Page page) {
        return mallShowSubjectReadDao.listPage(mallShowSubject, page);
    }

    /**
     * 查询所有
     * @param mallShowSubject 专题
     * @return 列表数据
     */
    @Override
    public List<MallShowSubject> list(MallShowSubject mallShowSubject) {
        return mallShowSubjectReadDao.listPage(mallShowSubject, null);
    }

    /**
     * 分页查询
     * @param mallShowSubjectQuery 展示商品主题
     * @param page 分页参数
     * @return 列表数据
     */
    @Override
    public List<MallShowSubjectWithAuthor> queryListPage(MallShowSubjectQuery mallShowSubjectQuery, Page page) {
        return mallShowSubjectReadDao.queryListPage(mallShowSubjectQuery, page);
    }

    @Override
    public List<MallShowSubject> findByMemberId(String memberId) {
        MallShowSubject mallShowSubject = new MallShowSubject();
        mallShowSubject.setMemberId(memberId);
        return mallShowSubjectReadDao.listPage(mallShowSubject, null);
    }

    @Override
    public List<MallShowSubject> batchList(@NotNull Set<String> ids, MallShowSubject mallShowSubject, Page page) {
        return null;
    }
}
